<?php


namespace app\cms\authCallBack;


use app\cms\model\merchant\merchantModel;
use iflow\Response;

class merchant
{

    /**
     * 用户是否已经开启商户
     * @return Response|bool
     */
    public function userMerchantExists(): Response|bool
    {
        $merchant = (new merchantModel()) -> findMerchant(session('userInfo')['uid']);

        if ($merchant -> isEmpty()) {
            return message()->unauthorized_error('请先申请开通商户');
        }

        if (intval($merchant['status']) !== 1) {
            return message() -> unauthorized_error('该商户已被冻结无法继续操作， 如有疑问请联系客服');
        }

        return false;
    }

    /**
     * 用户是否已经开启商户
     * @return Response|bool
     */
    public function userMerchantNotExists(): Response|bool
    {
        if ((new merchantModel()) -> findMerchant(session('userInfo')['uid']) -> isExists()) {
            return message()->unauthorized_error('你已开通或已申请商户');
        }
        return false;
    }

}